#include<iostream>
using namespace std;
const int N = 4e4 + 10;
int n, m;
int p[N];
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
int get(int x, int y)
{
	return x * n + y;
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n * n; i++) {
		p[i] = i;
	}
	int ans = 0;
	for (int i = 1; i <= m; i++) {
		int x, y;
		char d;
		cin >> x >> y >> d;
		x--, y--;
		int pa, pb;
		pa = get(x, y);
		if (d== 'D') {
			pb = get(x + 1, y);
		}
		else {
			pb = get(x, y + 1);
		}
		pa = find(pa);
		pb = find(pb);
		if (pa == pb) {
			ans = i;
			break;
		}
		else {
			p[pa] = pb;
		}
	}
	if (!ans) {
		cout << "draw" << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}